function integerReplacement(n: number): number {
  if (n === 1) return 0
  if (n % 2) {
      return Math.min(integerReplacement(n + 1), integerReplacement(n - 1)) + 1
  }
  return integerReplacement(n / 2) + 1
};